<?php session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';

}


?>

<!--lets get it -->
<? $topid = $_GET['topicid'];

//topic query again
//loop it!
$topicQuery = mysql_query("SELECT * FROM tblfrtopic WHERE topicid = '$topid' ");
//eto n ang loop
	while($row  =  mysql_fetch_array($topicQuery)):
	$topicid = $row['topicid'];
	$title 	 = $row['topictitle'];
	$content = $row['topicontent'];
	$date 	 = $row['topicdate'];
	$createby = $row['createdby'];
	$topicimg = $row['topicimg'];
	$createid = $row['createbyid'];
	$views 	  = $row['views'];
	$topiccat = $row['category'];
	
	if($topiccat == 'makabayan'):
		$catlink = 'viewMakabayan';
		$catego = 'Makabayan';
		//Filipino Section
		elseif($topiccat == 'filipino'):
		$catlink = 'viewFilipino';
		$catego = 'Filipino';
		//English Section
		elseif($topiccat == 'english'):
		$catlink = 'viewEnglish';
		$catego = 'English';
		//Math Section
		elseif($topiccat == 'math'):
		$catlink = 'viewMath';
		$catego = 'Math';
		//Science Section
		elseif($topiccat == 'science'):
		$catlink = 'viewScience';
		$catego = 'Science';
		//Others Section
		elseif($topiccat == 'others'):
		$catlink = 'viewOthers';
		$catego = 'Others';

endif;
	endwhile;
	
	//who post 
	
	$postby = mysql_query("SELECT * FROM tbluser WHERE userid = '$createid' ");
	while($memberRow = mysql_fetch_array($postby)):
		$postedBy = $memberRow['userid'];
		$ava 	  = $memberRow['avatar'];
	endwhile;
	$views+=1;
	mysql_query("UPDATE tblfrtopic SET views = '$views' WHERE topicid = '$topid'");
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>View Topic : <? print($title); ?> </title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
         <link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
    
</head>
<body>

 <div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
  <p> </p>
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left" class="date"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
          <!-- <div id="chef_ind">open chef -->
        <div id="welcome"> <!--open welcome -->
               <!-- <h2 class="guilded"></h2> -->
        </div> <!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>
  </div>
        
      <!--</div>close left -->
    <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3_students"><h1>Forum</h1> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg1o"><!--open booking -->

	
   <table width="650" border="0" align="center" bordercolorlight="#000000" class="tbcms" bgcolor="#ebf9b4">
	<tr>
    	<td colspan="6">
	<b>Forum</b> <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="<? print $catlink; ?>.php"><? print $catego; ?></a><img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="viewtopic.php?topicid=<? print $topicid; ?>"><strong><? print $title; ?></strong></strong></a>
    	</td>
    </tr>
<tr>
		<td align="left" background="catbg.png" colspan="5" class="cat"><? print $title; ?></td>
    </tr>
                      <tr>
                      <td valign="top" width="5%" rowspan="6">
                      <a class="postedby" href="userprofile.php?userid=<? print $postedbyid; ?>"><? print $postedby; ?></a><br />
                      <img src="avatar/<? print $ava; ?>" width="80" height="71" border="0" /></td>
                      </tr>

                      <tr>
                        <td width="58%" class="extra"><span class="thead">Title: </span><? print $title; ?></td>
                         <td width="30%" align="right" class="extra"><? print $date; ?></td>
                       
					</tr>
                      
                      <tr>
                        <td colspan="2">
                          <? echo "<div class='forumimg'><img src='topic_img/";
		if($topicimg == '')
		{ echo "defaultdp.png' "; }
		else
		{ echo "$topicimg' "; }
		
		echo " width='125px'/>'(click image to view larger)</div>";
						  print $content ;
						   ?>
                        </td>
                      </tr>
                      <tr>
                      <td align="right" colspan="2">
                      <?
                      $userid = $_SESSION['userid'];
	  
					  ?>&nbsp;
                      </td>
                      </tr>
</table>

<hr width="655" />

<? 
//delete here!


?>

<?


$replyquery = mysql_query("SELECT * from tblfrreply WHERE topicid = '$topicid' ORDER BY replyid ASC ");
	while($row2 = mysql_fetch_array($replyquery))
		{
		$replyid = $row2['replyid']; 
		$replycontent = $row2['replycontent']; 
		$replytime = $row2['replytime'];
		$replyby = $row2['replyby'];
		$replybyid = $row2['replybyid'];
		
		
		$replybyav = mysql_query("SELECT * from tbluser WHERE userid = '$replybyid' ");
			while($reprow = mysql_fetch_array($replybyav))
		{
			$replierid = $reprow['user'];
			$repavatar = $reprow['avatar'];
		}
		
		
		print '
		<table class="tbcms" width="655" border="0">
		<tr>
                      <td valign="top" width="13%" rowspan="6">
                      <a class="postedby" href="userprofile.php?userid='.$replybyid.'">'.$replyby.'</a><br />
                      <img src="avatar/'.$repavatar.'" width="75" height="75" border="0" /></td>
                      </tr>

                      <tr>
                        <td class="extra">Title: '.$title.'</td><td width="30%" align="right" class="extra">'.$replytime.'</td>
					</tr>
                      <tr>
                        <td colspan="2" height="1">
                          &nbsp;
                        </td>
                      </tr>

                      <tr>
                        <td colspan="2">
                          '.$replycontent.'
                        </td>
                      </tr>
					  <tr>
                        <td align="right" colspan="2">';
			
			
			
			if($_SESSION['user']=='admin' || $userid==$replybyid)
			
			{
				print '
				
				<a href="replyDelete.php?topicid='.$topid.'&replyid='.$replyid.'" class="otherlink">Delete</a>
				
				';
			
			}
			print '&nbsp;
						</td>
                    </tr>
				</table>
				<hr width="655" />
			
			';
                        
	
			/**/
		}



?>                
		
        
        <table align="right" height="40" width="800">
        <tr>
        <td align="right"><a href="reply.php?topicid=<? print $topicid; ?>" class="reply">Reply</a></td>
        </tr>
        
        </table>
    </div><!--close desc -->
   
        
         </div> <!--close container-->
   			
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
    <?php 
	  echo '<div id="footer_view">';
     include('footer_view.php');
      echo '</div>';	
	  ?>
        
     	
    
  


    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>
